
const jwt = require('jsonwebtoken')

const verifyToken = (req) => {
    let token = JSON.parse(req.headers.authorization).token
    let refreshToken = JSON.parse(req.headers.authorization).refreshToken
    let verifyRes
    jwt.verify(token, 'keyword', async (err) => {
        if (err) {
            console.log(1);
            jwt.verify(refreshToken, 'keyword', async (err) => {
                if (err) {
                    console.log(2);
                    verifyRes = { code: 4030, msg: '登录时间过长，请重新登录' }
                } else {
                    console.log(3);
                    verifyRes = { code: 401 }
                }
            })
        } else {
            console.log(4);
            verifyRes = { code: 200 }
        }
    })
    return verifyRes
}


module.exports = { verifyToken }